﻿using System;
using System.Collections.Generic;

namespace Inovout.Gis
{
    public abstract class Configuration
    {
        private IDictionary<string, string> properties;

        public Configuration()
        {
            properties = new Dictionary<string, string>();
        }


        public IDictionary<string, string> Properties
        {
            get { return properties; }
            set { properties = value; }
        }
        private static IDictionary<string, LayerMapping> layerMappingDictionaies = new Dictionary<string, LayerMapping>();
        private static IDictionary<Type, LayerMapping[]> mapLayerMappingDictionaries = new Dictionary<Type, LayerMapping[]>();
        public void AddLayerMapping(Type mapType, Type layerType,Type geometryType, params string[] tableNames)
        {
            List<LayerMapping> layerMappings = new List<LayerMapping>();
            foreach (string tableName in tableNames)
            {
                layerMappings.Add(new LayerMapping { TableName = tableName, LayerType = layerType,GeometryType=geometryType });
                layerMappingDictionaies.Add(tableName,layerMappings[layerMappings.Count-1] );
            }
            mapLayerMappingDictionaries.Add(mapType, layerMappings.ToArray());
        }
        public LayerMapping[] GetLayerMappings(Type mapType)
        {
            return mapLayerMappingDictionaries[mapType];
        }
        public abstract IGisSessionFactory BuildSessionFactory();

        internal LayerMapping GetLayerMapping(string tableName)
        {
            LayerMapping layerMapping;
            layerMappingDictionaies.TryGetValue(tableName, out layerMapping);
            return layerMapping;
        }
    }
}
